open Castling;;

module CharPG = ParserGenerator (CharToken);;
open CharPG;;

let rec digit = lazy !! (
	one_of_elements ['0'; '1'; '2'; '3'; '4'; '5'; '6'; '7'; '8'; '9']
)
and num = lazy !! (
	one_of ~name:"num" [
		"digit", digit;
		"digits", digit >> num
	]
)
and term = lazy !! (
	one_of ~name:"expr" [
		"num", position >> num;
		"", skip (element '(') >> sum >> skip (element ')')
	]
)
and prod = lazy !! (
	one_of ~name:"expr" [
		"", term;
		"mul", prod >> position_of (element '*') >> term;
		"div", prod >> position_of (element '/') >> term
	]	
)
and sum = lazy !! (
	one_of ~name:"expr" [
		"", prod;
		"add", sum >> position_of (element '+') >> prod;
		"sub", sum >> position_of (element '-') >> prod
	]
);;

debug := true;;
runtime_debug := true;;
error_printer := true;;
generate ~ast_module:"AST" ~parser_module:"Parser" sum;;
